<template>

  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
    </div>

    <div class="product-content">
      <el-form ref="form" :model="form" label-width="100px">
        <div class="table-wrap">
          <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
            <el-table-column prop="productName" label="商品名稱" width="360">
              <template #default="scope">
                <div class="product-info">
                  <div class="pic" style="width: 40px; height: 40px;"><img v-img-url="scope.row.productImage" alt="" /></div>
                  <div class="info">
                    <div class="name">{{ scope.row.productName }}</div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="title" label="活動名稱"></el-table-column>
            <el-table-column prop="stock" label="庫存"></el-table-column>
            <el-table-column prop="limitNum" label="限購數量"></el-table-column>
            <el-table-column prop="totalSales" label="累計銷量"></el-table-column>
            <el-table-column prop="joinNum" label="參與人數"></el-table-column>
            <el-table-column prop="statusText" label="狀態"></el-table-column>
            <el-table-column prop="remark" label="備註"></el-table-column>
            <el-table-column prop="createTime" label="申請時間"></el-table-column>
            <el-table-column fixed="right" label="操作" width="120">
              <template #default="scope">
                <el-button  @click="edit(scope.row)" type="text" size="small">修改</el-button>
                <el-button v-if="scope.row.status!=10" @click="delClick(scope.row)" type="text" size="small">刪除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage"
           :page-size="pageSize" layout="total, prev, pager, next, jumper"
          :total="totalDataNumber">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import BargainApi from '@/api/bargain';
export default {
  data() {
    return {
      formInline: {},
      form: {},
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*是否加载完成*/
      loading: true
    };
  },
  created() {
    /*获取列表*/
    this.getData();
  },
  methods: {
    /*获取列表*/
    getData() {
      let self = this;
      let Params = {};
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      BargainApi.myList(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {});
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getData();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    edit(row) {
      let self = this;
      ElMessageBox.confirm("修改後會自動下架該商品，並且需要平台重新審核，確認修改該紀錄嗎？", "提示", {
        type: 'warning'
      }).then(() => {
        this.$router.push('/activity/bargain/edit?bargainProductId=' + row.bargainProductId);
      });
    },
    /*删除*/
    delClick: function (row) {
      let self = this;
      ElMessageBox.confirm("刪除後不可恢復，確認刪除該紀錄嗎？", "提示", {
        type: 'warning'
      }).then(() => {
        BargainApi.delProduct({
          bargainProductId: row.bargainProductId
        }).then(data => {
          ElMessage({
            message: "刪除成功",
            type: 'success'
          });
          self.getData();
        });
      });
    }
  }
};
</script>

